
//leetcode：206.反转链表



class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 }

public class Solution {
    public ListNode reverseList(ListNode head) {
        //判断链表是否为空
        if(head == null) {
            return null;
        }
        ListNode prev = head;
        ListNode cur = head.next;
        ListNode tmp = null;
        while(cur != null) {
            tmp = cur.next;
            cur.next = prev;
            prev = cur;
            cur = tmp;
        }
        head.next = null;
        return prev;
    }
}
